#include "stdafx.h"

#include "TestRunner.h"

namespace Slow
{

    TESTCLASS(TestRunnerTests)
    {
        class CountingReporter : public TDD::Reporter
        {
            int m_count;
        public:
            CountingReporter() : m_count(0) {}
            int GetCount() const { return m_count; }
        private:
            virtual void ForEachFailure(const TDD::TestFailure&) {}
            virtual void ForEachTest   (const TDD::UnitTestInfo&) { ++m_count; }
        };

        TESTMETHOD(AlwaysFail)
        {
            TDD_FAILURE("a temporary test that always fails");
        }

        TESTMETHOD(NonExistantTestDll)
        {
            CountingReporter cr;
            TestRunner tr(TDD::Discriminator(), cr);
            TDD_VERIFY(false == tr.RunTests(L"bogus.dll"));
            TDD_VERIFY(0 == cr.GetCount());
        }

        TESTMETHOD(RunTestsInCurrentDll)
        {
            class WantFirstTestOnly : public TDD::Discriminator
            {
                bool m_first;
            public:
                WantFirstTestOnly() : m_first(true) {}
            private:
                virtual bool WantTest(const TDD::UnitTestInfo&)
                {
                    if (m_first)
                    {
                        m_first = false;
                        return true;
                    }
                    return false;
                }
            };

            // get self
            CString csFilename;
            ::GetModuleFileName(_AtlBaseModule.GetModuleInstance(), csFilename.GetBuffer(MAX_PATH), MAX_PATH);
            csFilename.ReleaseBuffer();

            CountingReporter cr;
            TestRunner tr(WantFirstTestOnly(), cr);
            TDD_VERIFY(true == tr.RunTests(CPath(csFilename)));
            TDD_VERIFY(1 == cr.GetCount());
        }
    };

}
